
var TreeView = function() {
	var o = new Object();
	
	// 初始化Tree
    o.init = function () {
    	
    	$('#left-side-tree').treeview({
    		data : this.getTreeData()
    	});
    	o.bindEvents();
    	
    }
    o.getTreeData = function () {
    	var fileTree ;
    	var callback = function(result){
    		fileTree = result.rows;
    	}
    	var options = {
            	async : false,
            	url: "tree/info",
            	success: callback
            }
        $.ajax(options);
        return fileTree;
    }
    // 绑定事件
    var self = o ;
    o.bindEvents = function() {
    	
    	$('#left-side-tree').on('nodeSelected', function(event, node) {

    		if(node.nodes == undefined){
    			//没有子节点 、 打开当前节点
    			
    		} else {
    			//有子节点、打开当前节点的子节点
    			currentDir = self.getCurrentDir(node);
    			enterDir(currentDir);
    		} 
			
    	}); 
    	
    }
    // 根据 text 获取 全路径
    o.getCurrentDir = function(node){
		var nodeId = node.nodeId;
		var wholePath = [node.text];
		while(true){
			
			// console.log(node.parentId === undefined)
    		if(node.parentId === undefined) break;			
    		parentNode = $('#left-side-tree').treeview('getParent', node.nodeId);
    		wholePath.unshift(parentNode.text);  		
			console.log(parentNode)   		
			node = parentNode;			
		}
		return wholePath.join("/");
    }
	return o;
}


